using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{

    public partial class VICC_GABEW
    {

        public void InsertICC_GABEW(DataRow dwData, int option = 1)
        {
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "INSERT INTO ICC_GABEW SELECT * FROM GABEW W WHERE W.GABBELEG>=:GABBELEG AND NOT EXISTS ( SELECT 1 FROM ICC_GABEW X WHERE X.GABBELEG=W.GABBELEG AND X.GABLFDNR=W.GABLFDNR)";
                    or1.Parameters.Add("GABBELEG", OracleType.NVarChar).Value = dwData["GABBELEG"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DeleteICC_GABEW(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM ICC_GABEW"
                 + " WHERE GABBELEG<=:GABBELEG:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public DataSet QueryICC_GABEW(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT NVL(MAX(GABBELEG),0) AS GABBELEG  FROM ICC_GABEW"; ;
                    break;
                case 2:
                    or1.CommandText = "SELECT NVL(MAX(GABBELEG),0) AS GABBELEG  FROM ICC_GABEW WHERE GABBUCHDAT<=:GABBUCHDAT:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 3:
                    or1.CommandText = "SELECT W.*,SCN FROM ICC_GABEW W JOIN GPDAT ON GABPARTIE=GPPARTIE LEFT JOIN ICC_GABBS X ON  W.GABBS=X.GABBS WHERE GABBUCHDAT=:GABBUCHDAT: AND GPSPPART=:GPSPPART: AND GPZWPART=:GPZWPART: AND GPFBPART=:GPFBPART:"; ;
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    break;
            }
            SResult = Connect2Proxy(or1); 
            SResult.Tables[0].TableName = "ICC_GABEW"; 
            return SResult;
        }

        public DataSet QGABEW07(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "SELECT W.*,SCN FROM ICC_GABEW W  LEFT JOIN ICC_GABBS X ON  W.GABBS=X.GABBS "
                + " WHERE GABMANDANT=:GABMANDANT: AND GABLO=:GABLO: AND GABLB=:GABLB: AND GABBUCHDAT=:GABBUCHDAT: AND GABART=:GABART: AND GABVAR=:GABVAR: AND GABFARBE=:GABFARBE: AND W.GABBS=:GABBS: "; ;
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "ICC_GABEW";
            return SResult;

        }

       
        public void UpdateICC_GABEW(DataRow dwData, string ITXDBVERSION = "50.24")
        {

            or1 = OracleDB.CreateCommand();
            #region====Command====
            or1.CommandText = " UPDATE ICC_GABEW SET GABBS=:GABBS,"
                + "EN=:EN,"
                + "SCN=:SCN "
                + " WHERE  "
                + "    ROWNID=:ROWNID ";
            #endregion
            #region====Parameters====
            or1.Parameters.Add("ROWNID", OracleType.NVarChar).Value = dwData["ROWNID"].ToString();
            or1.Parameters.Add("GABBS", OracleType.NVarChar).Value = dwData["GABBS"].ToString();
            or1.Parameters.Add("EN", OracleType.NVarChar).Value = dwData["EN"].ToString();
            or1.Parameters.Add("SCN", OracleType.NVarChar).Value = dwData["SCN"].ToString();
            #endregion
            Connect2Proxy(or1);
        }
        public void UGBW02(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE ICC_GABEW SET GABBUCHDAT=:GABBUCHDAT:"
                     + " WHERE GABMANDANT=:GABMANDANT: AND GABBELEG=:GABBELEG: AND  GABLFDNR=:GABLFDNR:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
    }
}
